home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / program / main22.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  46KB  |  1,704 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "DOpus.h"
  32. #include "music.h"
  33. #include "view.h"
  34.  
  35. dofilefunction(function,flags,sourcedir,destdir,act,inact,rexx)
  36. int function,flags;
  37. char *sourcedir,*destdir;
  38. int act,inact,rexx;
  39. {
  40.     int askeach=0,a,b,special=0,candoicon=1,old,specflags,noshow=0,err;
  41.     int sourcewild=0,destwild=0,firstset=0,breakout,rexarg,protstuff[2];
  42.     int pt=1,okayflag,show,lastfile,flag,exist,byte,count,data,mask=0,temp;
  43.     int globflag,noremove,doicons=0,total,value=0,progtype,blocksize,retval=0;
  44.     ULONG class;
  45.     USHORT code;
  46.     struct Directory *file,*tempfile,*nextfile,filebuf,dummyfile;
  47.     char *sourcename,*destname,*oldiconname,*newiconname;
  48.     char *buf,*buf1,*buf2,*namebuf,*srename,*drename,*ptr,*database;
  49.     static char tbuf[256],titlebuf[32];
  50.     struct DOpusDateTime datetime;
  51.     struct DOpusRemember *funckey;
  52.     struct dopusfiletype *type;
  53.     struct dopusfuncpar par;
  54.     struct DirectoryWindow *swindow,*dwindow;
  55.     struct InfoData __aligned infodata;
  56.     struct FileInfoBlock __aligned fileinfo;
  57.     struct DOpusArgsList arglist;
  58.     struct ViewData *viewdata=NULL;
  59.     BPTR filelock;
  60.     static int entry_depth;
  61.     char progress_copy=0,prog_indicator=0;
  62.  
  63.     if (act>-1) swindow=dopus_curwin[act];
  64.     else swindow=NULL;
  65.     if (inact>-1) dwindow=dopus_curwin[inact];
  66.     else dwindow=NULL;
  67.  
  68.     data=rexarg=0; funckey=NULL;
  69.     specflags=flags&~255; flags&=255;
  70.  
  71.     if (config->iconflags&ICONFLAG_DOUNTOICONS || func_external_file[0]) doicons=1;
  72.  
  73.     switch (function) {
  74.         case FUNC_PLAYST:
  75.             if (!MUSICBase) return(0);
  76.         case FUNC_PLAY:
  77.         case FUNC_LOOPPLAY:
  78.             if (MUSICBase) FlushModule();
  79.             break;
  80.     }
  81.  
  82.     /* Find the first file to work upon; if only one file specified,
  83.      use that */
  84.  
  85.     if (status_flags&STATUS_GLOBALFILE)                     /* kludge */
  86.         flags=FUNCFLAGS_FILES;
  87.  
  88.     total=-1;
  89.  
  90.     if (func_single_entry) {
  91.         file=func_single_entry;
  92.         globflag=1;
  93.     }
  94.     else if (swindow) {
  95.         globflag=0;
  96.         if (flags&FUNCFLAGS_DIRS) {
  97.             file=checkdirtot(swindow);                             /* First dir */
  98.             total=swindow->dirsel;
  99.             progtype=1;
  100.         }
  101.         if (flags&FUNCFLAGS_DEVS && !file) {
  102.             file=checkdevtot(swindow);                             /*    or dev */
  103.             total=swindow->dirsel;
  104.             progtype=1;
  105.         }
  106.         if (flags&FUNCFLAGS_FILES) {
  107.             file=checktot(swindow);                                /* First file */
  108.             total=swindow->filesel;
  109.             progtype=0;
  110.         }
  111.         if (flags==0 || flags&FUNCFLAGS_ANYTHING) {
  112.             file=checkalltot(swindow);
  113.             total=swindow->filesel+swindow->dirsel;                /* Anything   */
  114.             progtype=2;
  115.         }
  116.         if (!file && flags&FUNCFLAGS_ANYTHING) {
  117.             file=checkdevtot(swindow);
  118.             total=swindow->dirsel;
  119.             progtype=1;
  120.         }
  121.  
  122.       /* Name may be in ARexx */
  123.  
  124.         if (rexx && (tempfile=findfile(swindow,rexx_args[0],NULL))) {
  125.             ++rexarg;
  126.             file=tempfile;
  127.             func_single_entry=file;
  128.             strcpy(func_single_file,file->name);
  129.             globflag=1;
  130.         }
  131.     }
  132.  
  133.     if (!file) return(0);            /* No files selected, return */
  134.  
  135.     if (!(database=LAllocRemember(&funckey,3000,MEMF_CLEAR))) return(0);
  136.     sourcename=database; destname=database+300;
  137.     oldiconname=database+600; newiconname=database+900;
  138.     buf=database+1200; buf1=database+1500; buf2=database+1800;
  139.     namebuf=database+2100; srename=database+2400; drename=database+2700;
  140.  
  141.     if (swindow) scrdata_old_offset_store=swindow->offset; /* Store directory offset for auto-scroll */
  142.     else scrdata_old_offset_store=-1;
  143.  
  144.     status_justabort=count=0; namebuf[0]=0;
  145.  
  146.     /* Bump entry depth to check for recursion */
  147.  
  148.     ++entry_depth;
  149.  
  150.     /* Do initial setting up functions */
  151.  
  152.     switch (function) {
  153.         case FUNC_READ:
  154.         case FUNC_HEXREAD:
  155.         case FUNC_ANSIREAD:
  156.         case FUNC_SMARTREAD:
  157.             if (!globflag &&
  158.                 !(viewdata=LAllocRemember(&funckey,sizeof(struct ViewData),MEMF_CLEAR)))
  159.                 goto endfunction;
  160.         case FUNC_LOOPPLAY:
  161.         case FUNC_SHOW:
  162.             total=-1;
  163.         case FUNC_PLAY:
  164.             candoicon=0;
  165.             break;
  166.         case FUNC_DELETE:
  167.             askeach=1;
  168.             if (config->deleteflags&DELETE_ASK && !globflag) {
  169.                 /* Ask for confirmation before commencing delete */
  170.                 displaydirgiven(act,file,0);
  171.                 if (!(a=simplerequest(globstring[STR_REALLY_DELETE],
  172.                     globstring[STR_DELETE],str_cancelstring,globstring[STR_ALL],NULL))) {
  173.                     endfollow(act);
  174.                     myabort();
  175.                     goto endfunction;
  176.                 }
  177.                 if (a==2) askeach=0;
  178.             }
  179.             glob_unprotect_all=0;
  180.             break;
  181.         case FUNC_RENAME:
  182.             if (rexx) {
  183.                 if (rexx_argcount<2) goto endfunction;
  184.                 strcpy(srename,rexx_args[0]);
  185.                 strcpy(drename,rexx_args[1]);
  186.                 if (strchr(srename,'*')) sourcewild=1;
  187.                 if (strchr(drename,'*')) destwild=1;
  188.                 else {
  189.                     strcpy(namebuf,drename);
  190.                     firstset=1;
  191.                 }
  192.             }
  193.             else while (file) {
  194.                 if (file->selected) {
  195.                     strcpy(srename,file->name); strcpy(drename,file->name);
  196.                     displaydirgiven(act,file,0);
  197.                     if (!(a=getrenamedata(srename,drename)) ||
  198.                         !srename[0] || !drename[0]) {
  199.                         endfollow(act);
  200.                         myabort();
  201.                         goto endfunction;
  202.                     }
  203.                     if (a==1) {
  204.                         if (strchr(srename,'*')) sourcewild=1;
  205.                         if (strchr(drename,'*')) destwild=1;
  206.                         else {
  207.                             strcpy(namebuf,drename);
  208.                             firstset=1;
  209.                             total=-1;
  210.                         }
  211.                         break;
  212.                     }
  213.                 }
  214.                 ++value;
  215.                 file=file->next;
  216.             }
  217.             if (!file) {
  218.                 endfollow(act);
  219.                 goto endfunction;
  220.             }
  221.             askeach=1;
  222.             break;
  223.         case FUNC_MOVE:
  224.             if (destdir[0] && !(checksame(sourcedir,destdir,1))) goto endfunction;
  225.         case FUNC_MOVEAS:
  226.             if (!(checkdest(inact))) goto endfunction;
  227.             if (!(config->existflags&REPLACE_ALWAYS)) askeach=1;
  228.             progress_copy=1;
  229.             break;
  230.         case FUNC_COPY:
  231.             if (destdir[0] && !(checksame(sourcedir,destdir,1))) goto endfunction;
  232.         case FUNC_COPYAS:
  233.             if (!(checkdest(inact))) goto endfunction;
  234.             if (!(config->existflags&REPLACE_ALWAYS)) askeach=1;
  235.             progress_copy=1;
  236.             if (!(specflags&FUNCFLAGS_COPYISCLONE) && config->copyflags©_CHECK) {
  237.                 old=scrdata_old_offset_store;
  238.                 if (!globflag) {
  239.                     a=0;
  240.                     tempfile=file;
  241.                     while (tempfile) {
  242.                         if (tempfile->selected && tempfile->type>=ENTRY_DIRECTORY &&
  243.                             tempfile->size==-1) {
  244.                             a=1;
  245.                             break;
  246.                         }
  247.                         tempfile=tempfile->next;
  248.                     }
  249.                     if (!a || simplerequest(globstring[STR_SIZES_NOT_KNOWN],
  250.                         globstring[STR_YES],globstring[STR_NO],NULL)) {
  251.                         if (status_justabort ||
  252.                             (!(dofilefunction(FUNC_BYTE,FUNCFLAGS_BYTEISCHECKFIT,
  253.                                 sourcedir,destdir,act,inact,0)) &&
  254.                             !(simplerequest(globstring[STR_ENTRIES_MAY_NOT_FIT],
  255.                             globstring[STR_CONTINUE],str_cancelstring,NULL)))) {
  256.                             myabort();
  257.                             goto endfunction;
  258.                         }
  259.                     }
  260.                 }
  261.                 scrdata_old_offset_store=old;
  262.             }
  263.             break;
  264.         case FUNC_HUNT:
  265.             if (rexx && rexx_argcount>0) strcpy(str_hunt_name,rexx_args[rexarg]);
  266.             else if (!(whatsit(globstring[STR_ENTER_HUNT_PATTERN],80,str_hunt_name,NULL)) ||
  267.                 !str_hunt_name[0]) {
  268.                 myabort();
  269.                 goto endfunction;
  270.             }
  271.             LParsePatternI(str_hunt_name,str_hunt_name_parsed);
  272.             CopyMem(str_hunt_name_parsed,buf2,170);
  273.             candoicon=0;
  274.             break;
  275.         case FUNC_PRINT:
  276.             if (globflag) {
  277.                 StrCombine(sourcename,sourcedir,file->name,256);
  278.                 arglist.single_file=sourcename;
  279.                 arglist.file_list=NULL;
  280.                 arglist.last_select=NULL;
  281.             }
  282.             else {
  283.                 arglist.single_file=NULL;
  284.                 arglist.file_window=act;
  285.                 arglist.file_list=(APTR)file;
  286.             }
  287.             dopus_print(rexx,&arglist,0,str_arexx_portname,NULL);
  288.             goto endfunction;
  289.             break;
  290.         case FUNC_COMMENT:
  291.             candoicon=0;
  292.         case FUNC_DATESTAMP:
  293.         case FUNC_PROTECT:
  294.             askeach=1;
  295.             break;
  296.         case FUNC_ENCRYPT:
  297.             if (!(checkdest(inact)) || !(checksame(sourcedir,destdir,1)))
  298.                 goto endfunction;
  299.             if (!(config->existflags&REPLACE_ALWAYS)) askeach=1;
  300.             if (rexx && rexx_argcount>0) strcpy(buf2,rexx_args[rexarg]);
  301.             else if (!(whatsit(globstring[STR_ENTER_PASSWORD],20,buf2,NULL)) ||
  302.                 !buf2[0]) {
  303.                 myabort();
  304.                 goto endfunction;
  305.             }
  306.             if (buf2[0]=='-') {
  307.                 data=0;
  308.                 strcpy(buf2,&buf2[1]);
  309.             }
  310.             else data=1;
  311.             candoicon=0;
  312.             progress_copy=1;
  313.             break;
  314.         case FUNC_SEARCH:
  315.             if (rexx && rexx_argcount>0) strcpy(str_search_string,rexx_args[rexarg]);
  316.             else {
  317.                 if (!(get_search_data(str_search_string,&search_flags,Window,scr_font[FONT_REQUEST]))) {
  318.                     myabort();
  319.                     goto endfunction;
  320.                 }
  321.             }
  322.             candoicon=0;
  323.             askeach=1;
  324.             break;
  325.         case FUNC_RUN:
  326.             candoicon=0;
  327.             break;
  328.         case FUNC_ADDICON:
  329.             askeach=1;
  330.             candoicon=0;
  331.             break;
  332.         case FUNC_ICONINFO:
  333.             candoicon=0;
  334.             total=-1;
  335.             break;
  336.         case FUNC_AUTO:
  337.         case FUNC_AUTO2:
  338.         case FUNC_AUTO3:
  339.         case FUNC_AUTO4:
  340.             dostatustext(globstring[STR_INTERROGATING_FILES]);
  341.             candoicon=0;
  342.             total=-1;
  343.             break;
  344.         case FUNC_BYTE:
  345.             candoicon=0;
  346.             special=2;
  347.             count=1;
  348.             main_proc->pr_WindowPtr=(APTR)-1;
  349.             if (filelock=Lock(destdir,ACCESS_READ)) {
  350.                 Info(filelock,&infodata);
  351.                 UnLock(filelock);
  352.                 blocksize=infodata.id_BytesPerBlock;
  353.             }
  354.             else blocksize=512;
  355.             if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
  356.             total=-1;
  357.             break;
  358.     }
  359.  
  360.     if (!(config->dynamicflags&UPDATE_PROGRESSIND_COPY)) progress_copy=0;
  361.  
  362.     endnotifies();
  363.  
  364.     if (config->dynamicflags&UPDATE_PROGRESSINDICATOR &&
  365.         (progress_copy || total>1)) {
  366.         char *title=NULL;
  367.         int x;
  368.  
  369.         for (x=0;;x++) {
  370.             if (!commandlist[x].name) break;
  371.             if (commandlist[x].function==function &&
  372.                 !(commandlist[x].flags&RCL_SYNONYM)) {
  373.                 title=commandlist[x].name;
  374.                 break;
  375.             }
  376.         }
  377.  
  378.         if (title) StrCombine(titlebuf,title,"...",32);
  379.         else strcpy(titlebuf,"Directory Opus");
  380.  
  381.         if (total>1) dotaskmsg(hotkeymsg_port,PROGRESS_OPEN,value,total,titlebuf,progress_copy);
  382.         else dotaskmsg(hotkeymsg_port,PROGRESS_OPEN,1,1,titlebuf,progress_copy);
  383.         prog_indicator=1;
  384.     }
  385.  
  386.     while (file) {
  387.         if (status_haveaborted) {
  388.             myabort();
  389.             break;
  390.         }
  391.         nextfile=file->next;
  392.  
  393.         if (!file->selected && !globflag) {
  394.             file=nextfile;
  395.             continue;
  396.         }
  397.  
  398.         if (doicons && candoicon && !(isicon(file->name))) {
  399.             StrCombine(oldiconname,file->name,".info",256);
  400.             StrCombine(buf1,sourcedir,oldiconname,256);
  401.             if (!(CheckExist(buf1,NULL))) oldiconname[0]=0;
  402.         }
  403.         else oldiconname[0]=0;
  404.  
  405.         if (prog_indicator) {
  406.             if (progtype==1 && file->type>=ENTRY_DEVICE) ++value;
  407.             else if (progtype==0 && file->type<=ENTRY_FILE) ++value;
  408.             else if (progtype==2) ++value;
  409.             if (total>1) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,value,total,NULL,0);
  410.             else dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,1,1,NULL,0);
  411.             if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-2,0,file->name,1);
  412.         }
  413.  
  414.         lastfile=flag=breakout=0;
  415.  
  416. functionloop:
  417.         StrCombine(sourcename,sourcedir,file->name,256);
  418.         if (!special || count==0 ||
  419.             (special==2 && file->type>=0)) {
  420.             dofilename(sourcename);
  421.             displaydirgiven(act,file,0);
  422.         }
  423.         if (!firstset && !lastfile && !namebuf[0]) strcpy(namebuf,file->name);
  424.         else if (lastfile) strcpy(namebuf,BaseName(newiconname));
  425.         okayflag=a=0; show=-1;
  426.  
  427.         if (func_external_file[0] || file==&dummyfile) noremove=1;
  428.         else noremove=0;
  429.  
  430.         switch (function) {
  431.             case FUNC_AUTO:
  432.             case FUNC_AUTO2:
  433.             case FUNC_AUTO3:
  434.             case FUNC_AUTO4:
  435.                 if (function==FUNC_AUTO) a=FTFUNC_AUTOFUNC1;
  436.                 else if (function==FUNC_AUTO2) a=FTFUNC_AUTOFUNC2;
  437.                 else if (function==FUNC_AUTO3) a=FTFUNC_AUTOFUNC3;
  438.                 else if (function==FUNC_AUTO4) a=FTFUNC_AUTOFUNC4;
  439.                 okayflag=1;
  440.                 if (file->type<=ENTRY_FILE) {
  441.                     if ((type=checkfiletype(sourcename,a,0))) {
  442.                         char title[256];
  443.  
  444.                         par.which=type->which[a]; par.stack=type->stack[a];
  445.                         par.key=par.qual=0;
  446.                         par.pri=type->pri[a]; par.delay=type->delay[a];
  447.                         status_previousabort=0;
  448.                         if (status_iconified && status_flags&STATUS_ISINBUTTONS)
  449.                             strcpy(func_external_file,sourcename);
  450.                         if (type->actionstring[a][0]) {
  451.                             do_title_string(type->actionstring[a],title,0,file->name);
  452.                             dostatustext(title);
  453.                         }
  454.                         else title[0]=0;
  455.                         dofunctionstring(type->function[a],file->name,title,&par);
  456.                         if (status_previousabort) status_haveaborted=1;
  457.                     }
  458.                     else {
  459.                         lsprintf(buf,globstring[STR_NOT_IDENTIFIED],file->name);
  460.                         dostatustext(buf);
  461.                     }
  462.                 }
  463.                 break;
  464.  
  465.             case FUNC_BYTE:
  466.                 if (file->type>=ENTRY_DIRECTORY &&
  467.                     (file->size<0 || (specflags&FUNCFLAGS_BYTEISCHECKFIT &&
  468.                     (file->userdata==0 || file->userdata2!=blocksize)))) {
  469.                     if ((a=recursedir(sourcename,NULL,R_GETBYTES,blocksize))==-10) {
  470.                         myabort();
  471.                         break;
  472.                     }
  473.                     file->userdata=dos_global_blocksneeded;
  474.                     file->userdata2=blocksize;
  475.                     setdirsize(file,dos_global_bytecount,act);
  476.                     refreshwindow(act,0);
  477.                 }
  478.                 if (file->type>=ENTRY_DIRECTORY) data+=file->userdata+1;
  479.                 else {
  480.                     a=(file->size+(blocksize-1))/blocksize;
  481.                     data+=a+(a/72)+1;
  482.                 }
  483.                 if (doicons && !(isicon(file->name))) {
  484.                     StrCombine(oldiconname,file->name,".info",256);
  485.                     b=-1;
  486.                     if (file=findfile(swindow,oldiconname,NULL)) {
  487.                         if (!file->selected) b=file->size;
  488.                     }
  489.                     else {
  490.                         StrCombine(tbuf,sourcedir,oldiconname,256);
  491.                         if (lockandexamine(tbuf,&fileinfo)) b=fileinfo.fib_Size;
  492.                     }
  493.                     if (b>-1) {
  494.                         a=(b+(blocksize-1))/blocksize;
  495.                         data+=a+(a/72)+1;
  496.                     }
  497.                     oldiconname[0]=0;
  498.                 }
  499.                 file=NULL;
  500.                 okayflag=1;
  501.                 break;
  502.  
  503.             case FUNC_RUN:
  504.                 if (file->type<=ENTRY_FILE) {
  505.                     if (checkexec(sourcename)) {
  506.                         if ((a=dorun(sourcename,1,0))==-1) break;
  507.                         else if (a && a!=-2) okayflag=1;
  508.                     }
  509.                     else if (file->protection&FIBF_SCRIPT) {
  510.                         struct dopusfuncpar par;
  511.  
  512.                         lsprintf(buf,"Execute \"%s\"",sourcename);
  513.                         defaultpar(&par);
  514.                         dofunctionstring(buf,NULL,NULL,&par);
  515.                         okayflag=1;
  516.                     }
  517.                 }
  518.                 break;
  519.  
  520.             case FUNC_DELETE:
  521.                 if (file->type>=ENTRY_DIRECTORY) {
  522.                     if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],
  523.                         glob_unprotect_all,0))==-1) {
  524.                         myabort();
  525.                         break;
  526.                     }
  527.                     else if (a>0) {
  528.                         if (a==2) glob_unprotect_all=1;
  529.                         if (!noremove) removefile(file,swindow,act,1); file=NULL;
  530.                         okayflag=1;
  531.                     }
  532. /*
  533.                     if (DeleteFile(sourcename)) {
  534.                         if (!noremove) removefile(file,swindow,act,1); file=NULL;
  535.                         okayflag=1;
  536.                     }
  537. */
  538.                     else if (a<0) {
  539.                         if ((a=IoErr())==ERROR_DELETE_PROTECTED &&
  540.                             config->deleteflags&DELETE_SET) {
  541.                             if (!flag) {
  542.                                 flag=1;
  543.                                 SetProtection(sourcename,0);
  544.                                 goto functionloop;
  545.                             }
  546.                         }
  547.                         else if (a==ERROR_OBJECT_NOT_FOUND) {
  548.                             if (!noremove) removefile(file,swindow,act,1);
  549.                             file=NULL;
  550.                             okayflag=1;
  551.                         }
  552.                         else if (a==ERROR_DIRECTORY_NOT_EMPTY) {
  553.                             if (config->deleteflags&DELETE_DIRS && askeach) {
  554.                                 lsprintf(buf2,globstring[STR_NOT_EMPTY],file->name);
  555.                                 if (!(a=simplerequest(buf2,globstring[STR_DELETE],
  556.                                     globstring[STR_LEAVE],globstring[STR_ALL],globstring[STR_ABORT],NULL))) {
  557.                                     okayflag=1;
  558.                                     break;
  559.                                 }
  560.                                 if (a==2) askeach=0;
  561.                                 else if (a==3) {
  562.                                     myabort();
  563.                                     break;
  564.                                 }
  565.                             }
  566.                             TackOn(sourcename,NULL,256);
  567.                             a=recursedir(sourcename,NULL,R_DELETE,0);
  568.                             sourcename[strlen(sourcename)-1]=0;
  569.                             if (!a) {
  570.                                 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],
  571.                                     glob_unprotect_all,1))==-1) {
  572.                                     myabort();
  573.                                     break;
  574.                                 }
  575.                                 else if (a==1 || a==2) {
  576.                                     if (a==2) glob_unprotect_all=1;
  577.                                     if (!noremove) removefile(file,swindow,act,1); file=NULL;
  578.                                     okayflag=1;
  579.                                 }
  580.                                 else {
  581.                                     setdirsize(file,dos_global_bytecount-dos_global_deletedbytes,act);
  582.                                     okayflag=1;
  583.                                 }
  584.                             }
  585.                             else {
  586.                                 setdirsize(file,file->size-dos_global_deletedbytes,act);
  587.                                 refreshwindow(act,0);
  588.                             }
  589.                         }
  590.                         else {
  591.                             doerror((a=IoErr()));
  592.                             if ((a=checkerror(globstring[STR_DELETING],file->name,a))==3) {
  593.                                 myabort();
  594.                                 break;
  595.                             }
  596.                             if (a==1) goto functionloop;
  597.                         }
  598.                     }
  599.                     show=act;
  600.                     break;
  601.                 }
  602.                 if (config->deleteflags&DELETE_FILES && askeach && !lastfile) {
  603.                     lsprintf(buf2,globstring[STR_WISH_TO_DELETE],file->name);
  604.                     if (!(a=simplerequest(buf2,globstring[STR_DELETE],globstring[STR_LEAVE],
  605.                         globstring[STR_ALL],globstring[STR_ABORT],NULL))) {
  606.                         okayflag=1;
  607.                         break;
  608.                     }
  609.                     if (a==2) askeach=0;
  610.                     else if (a==3) {
  611.                         myabort();
  612.                         break;
  613.                     }
  614.                 }
  615.                 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],
  616.                     glob_unprotect_all,1))==-1) {
  617.                     myabort();
  618.                     break;
  619.                 }
  620.                 else if (a) {
  621.                     if (a==2) glob_unprotect_all=1;
  622.                     if (!noremove) removefile(file,swindow,act,1); file=NULL;
  623.                     show=act;
  624.                     okayflag=1;
  625.                 }
  626.                 break;
  627.  
  628.             case FUNC_RENAME:
  629.                 if (firstset || lastfile) a=1;
  630.                 else if (!destwild) {
  631.                     if (!(a=whatsit(globstring[STR_ENTER_NEW_NAME],30,namebuf,
  632.                         globstring[STR_SKIP]))) {
  633.                         myabort();
  634.                         break;
  635.                     }
  636.                     if (a==2) {
  637.                         file=NULL;
  638.                         okayflag=1;
  639.                         oldiconname[0]=0;
  640.                         break;
  641.                     }
  642.                 }
  643.                 else if (!sourcewild) a=getwildrename("*",drename,file->name,namebuf);
  644.                 else if (sourcewild) a=getwildrename(srename,drename,file->name,namebuf);
  645.                 firstset=0;
  646.                 if (a) {
  647.                     if (lastfile) StrCombine(destname,sourcedir,newiconname,256);
  648.                     else {
  649.                         if (doicons && oldiconname[0]) namebuf[25]=0;
  650.                         else namebuf[30]=0;
  651.                         StrCombine(destname,sourcedir,namebuf,256);
  652.                         StrCombine(newiconname,namebuf,".info",256);
  653.                     }
  654.                     if (!(Rename(sourcename,destname))) {
  655.                         if ((a=IoErr())==ERROR_OBJECT_EXISTS) {
  656.                             if (askeach) {
  657.                                 if (!lastfile) {
  658.                                     if (!(a=checkexistreplace(sourcename,destname,&file->date,destwild,1)))
  659.                                         break;
  660.                                     if (a==2) {
  661.                                         if (!destwild) goto functionloop;
  662.                                         askeach=0;
  663.                                     }
  664.                                     else if (a==3) {
  665.                                         myabort();
  666.                                         break;
  667.                                     }
  668.                                 }
  669.                             }
  670.                             if ((a=delfile(destname,namebuf,globstring[STR_DELETING],1,1))==-2) {
  671.                                 if (!(a=recursedir(destname,NULL,R_DELETE,0))) a=1;
  672.                                 else if (a==-10) a=-1;
  673.                             }
  674.                             if (a==-1) {
  675.                                 myabort();
  676.                                 break;
  677.                             }
  678.                             if (a) {
  679.                                 if ((tempfile=findfile(swindow,namebuf,NULL))) {
  680.                                     if (tempfile==nextfile) nextfile=tempfile->next;
  681.                                     removefile(tempfile,swindow,act,1);
  682.                                 }
  683.                                 firstset=1;
  684.                                 goto functionloop;
  685.                             }
  686.                         }
  687.                         doerror(a);
  688.                         if ((a=checkerror(globstring[STR_RENAMING],file->name,a))==3) {
  689.                             myabort();
  690.                             break;
  691.                         }
  692.                         if (a==1) goto functionloop;
  693.                     }
  694.                     else {
  695.                         if (file->type>=ENTRY_DIRECTORY) {
  696.                             StrCombine(buf,sourcedir,file->name,256); TackOn(buf,NULL,256);
  697.                             StrCombine(buf1,sourcedir,namebuf,256); TackOn(buf1,NULL,256);
  698.                             renamebuffers(buf,buf1);
  699.                         }
  700.                         if (!noremove){
  701.                             if (act>-1 && config->sortmethod[act]==DISPLAY_NAME) {
  702.                                 CopyMem((char *)file,(char *)&filebuf,sizeof(struct Directory));
  703.                                 if (file->comment) strcpy(buf2,file->comment);
  704.                                 else buf2[0]=0;
  705.                                 removefile(file,swindow,act,0); file=NULL;
  706.                                 addfile(swindow,act,namebuf,filebuf.size,filebuf.type,&filebuf.date,
  707.                                     buf2,filebuf.protection,filebuf.subtype,1,NULL,NULL,
  708.                                     filebuf.owner_id,filebuf.group_id);
  709.                             }
  710.                             else strcpy(file->name,namebuf);
  711.                             if (lastfile) refreshwindow(act,0);
  712.                         }
  713.                         okayflag=1;
  714.                     }
  715.                 }
  716.                 else okayflag=1;
  717.                 break;
  718.  
  719.             case FUNC_MOVEAS:
  720.                 if (!lastfile && !flag) {
  721.                     if (rexx && rexx_argcount>1) strcpy(namebuf,rexx_args[1]);
  722.                     else {
  723.                         if (!(a=whatsit(globstring[STR_ENTER_NEW_NAME_MOVE],30,
  724.                             namebuf,globstring[STR_SKIP]))) {
  725.                             myabort();
  726.                             break;
  727.                         }
  728.                         if (a==2) {
  729.                             file=NULL;
  730.                             okayflag=1;
  731.                             oldiconname[0]=0;
  732.                             break;
  733.                         }
  734.                     }
  735.                     if (doicons && oldiconname[0]) namebuf[25]=0;
  736.                     else namebuf[30]=0;
  737.                 }
  738.             case FUNC_MOVE:
  739.                 if (lastfile) strcpy(destname,newiconname);
  740.                 else {
  741.                     StrCombine(destname,destdir,namebuf,256);
  742.                     StrCombine(newiconname,destname,".info",256);
  743.                 }
  744.                 if (!(checksame(destdir,sourcename,0))) break;
  745.                 if ((exist=CheckExist(destname,NULL))) {
  746.                     if (askeach) {
  747.                         if ((a=checkexistreplace(sourcename,destname,&file->date,(function==FUNC_MOVE),1))==3) {
  748.                             myabort();
  749.                             break;
  750.                         }
  751.                         if (!a) break;
  752.                         if (a==2) {
  753.                             if (function==FUNC_MOVEAS) goto functionloop;
  754.                             askeach=0;
  755.                         }
  756.                     }
  757.                     if ((a=delfile(destname,namebuf,globstring[STR_MOVING],1,1))==-1) {
  758.                         myabort();
  759.                         break;
  760.                     }
  761.                     if (!a) {
  762.                         doerror(ERROR_OBJECT_EXISTS);
  763.                         break;
  764.                     }
  765.                     if (a && (tempfile=findfile(dwindow,namebuf,NULL)))
  766.                         removefile(tempfile,dwindow,inact,0);
  767.                 }
  768.                 if (!(Rename(sourcename,destname))) {
  769.                     if ((exist<0 || file->type<=ENTRY_FILE) &&
  770.                         (a=IoErr())!=ERROR_RENAME_ACROSS_DEVICES) {
  771.                         doerror(a);
  772.                         if ((a=checkerror(globstring[STR_MOVING],file->name,a))==3) {
  773.                             myabort();
  774.                             break;
  775.                         }
  776.                         if (a==1) goto functionloop;
  777.                     }
  778.                     else {
  779.                         if (file->type>=ENTRY_DIRECTORY) {
  780.                             a=recursedir(sourcename,destname,R_COPY|R_DELETE,0);
  781.                             if (a==0) {
  782.                                 if (!func_external_file[0])
  783.                                     setdirsize(file,dos_global_bytecount-dos_global_deletedbytes,act);
  784.                             }
  785.                             else if (status_justabort || a<0) {
  786.                                 if (a!=-10) {
  787.                                     if ((a=checkerror(globstring[STR_MOVING],file->name,IoErr()))==3)
  788.                                         a=-10;
  789.                                     else if (a==1) goto functionloop;
  790.                                 }
  791.                                 if (!func_external_file[0]) {
  792.                                     setdirsize(file,file->size-dos_global_deletedbytes,act);
  793.                                     refreshwindow(act,0);
  794.                                 }
  795.                                 if (CheckExist(destname,NULL)) {
  796.                                     if (exist) {
  797.                                         if (tempfile=findfile(dwindow,namebuf,NULL))
  798.                                             removefile(tempfile,dwindow,inact,0);
  799.                                     }
  800.                                     addfile(dwindow,inact,namebuf,dos_global_copiedbytes,
  801.                                         file->type,&file->date,file->comment,
  802.                                         file->protection,file->subtype,1,NULL,NULL,
  803.                                         file->owner_id,file->group_id);
  804.                                 }
  805.                                 if (a==-10) myabort();
  806.                                 else status_justabort=0;
  807.                                 break;
  808.                             }
  809.                             if (!(tempfile=findfile(dwindow,namebuf,NULL))) {
  810.                                 addfile(dwindow,inact,namebuf,exist?-1:dos_global_copiedbytes,file->type,
  811.                                     &file->date,file->comment,file->protection,
  812.                                     file->subtype,1,NULL,NULL,file->owner_id,file->group_id);
  813.                             }
  814.                             else {
  815.                                 setdirsize(tempfile,exist?-1:dos_global_copiedbytes,act);
  816.                                 refreshwindow(inact,0);
  817.                             }
  818.                             if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],1,1))==-1) {
  819.                                 myabort();
  820.                                 break;
  821.                             }
  822.                             if (a==1) {
  823.                                 if (!noremove) removefile(file,swindow,act,1);
  824.                                 file=NULL;
  825.                             }
  826.                             okayflag=1;
  827.                         }
  828.                         else {
  829.                             if (!(a=copyfile(sourcename,destname,&err,-1,NULL,0))) {
  830.                                 doerror(err);
  831.                                 if ((a=checkerror(globstring[STR_MOVING],file->name,err))==3) {
  832.                                     myabort();
  833.                                     break;
  834.                                 }
  835.                                 if (a==1) goto functionloop;
  836.                             }
  837.                             else if (a==-1) {
  838.                                 myabort();
  839.                                 break;
  840.                             }
  841.                             else if (lockandexamine(destname,&fileinfo)) {
  842.                                 addfile(dwindow,inact,
  843.                                     fileinfo.fib_FileName,
  844.                                     fileinfo.fib_Size,
  845.                                     fileinfo.fib_DirEntryType,
  846.                                     &fileinfo.fib_Date,
  847.                                     fileinfo.fib_Comment,
  848.                                     fileinfo.fib_Protection,
  849.                                     file->subtype,1,NULL,NULL,
  850.                                     fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
  851.                                 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],1,1))==-2) {
  852.                                     if (!(a=recursedir(sourcename,NULL,R_DELETE,0))) a=1;
  853.                                     else if (a==-10) {
  854.                                         myabort();
  855.                                         break;
  856.                                     }
  857.                                 }
  858.                                 if (a==-1) {
  859.                                     myabort();
  860.                                     break;
  861.                                 }
  862.                                 if (a) {
  863.                                     if (!noremove) removefile(file,swindow,act,1); file=NULL;
  864.                                 }
  865.                                 else oldiconname[0]=0;
  866.                                 okayflag=1;
  867.                             }
  868.                         }
  869.                         show=act;
  870.                         seename(inact);
  871.                     }
  872.                 }
  873.                 else {
  874.                     if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,100,100,file->name,1);
  875.                     addfile(dwindow,inact,namebuf,file->size,file->type,&file->date,
  876.                         file->comment,file->protection,file->subtype,1,NULL,NULL,
  877.                         file->owner_id,file->group_id);
  878.                     if (!noremove) removefile(file,swindow,act,1); file=NULL;
  879.                     okayflag=1;
  880.                 }
  881.                 break;
  882.  
  883.             case FUNC_COPYAS:  /* If flag is set then won't ask for new name */
  884.                 if (!lastfile && !flag) {
  885.                     if (rexx && rexx_argcount>1) strcpy(namebuf,rexx_args[1]);
  886.                     else {
  887.                         if (!(a=whatsit(globstring[STR_ENTER_NEW_NAME],30,namebuf,
  888.                             globstring[STR_SKIP]))) {
  889.                             myabort();
  890.                             break;
  891.                         }
  892.                         if (a==2) {
  893.                             okayflag=1;
  894.                             file=NULL;
  895.                             oldiconname[0]=0;
  896.                             break;
  897.                         }
  898.                         if (LStrCmpI(sourcedir,destdir)==0 && LStrCmpI(namebuf,file->name)==0) {
  899.                             okayflag=1; oldiconname[0]=0;
  900.                             break;
  901.                         }
  902.                     }
  903.                     if (doicons && oldiconname[0]) namebuf[25]=0;
  904.                     else namebuf[30]=0;
  905.                 }
  906.             case FUNC_COPY:
  907.                 if (lastfile) strcpy(destname,newiconname);
  908.                 else {
  909.                     StrCombine(destname,destdir,namebuf,256);
  910.                     StrCombine(newiconname,destname,".info",256);
  911.                 }
  912.                 if (!(checksame(destdir,sourcename,0))) break;
  913.                 if ((exist=CheckExist(destname,NULL)) && askeach) {
  914.                     if ((a=checkexistreplace(sourcename,destname,&file->date,
  915.                         (function==FUNC_COPY),1))==3) {
  916.                         myabort();
  917.                         break;
  918.                     }
  919.                     if (!a) break;
  920.                     if (a==2) {
  921.                         if (function==FUNC_COPYAS) goto functionloop;
  922.                         askeach=0;
  923.                     }
  924.                 }
  925.                 if (exist<0) {
  926.                     if ((a=delfile(destname,file->name,globstring[STR_COPYING],1,1))==-1) {
  927.                         myabort();
  928.                         break;
  929.                     }
  930.                     if (!a) {
  931.                         doerror(ERROR_OBJECT_EXISTS);
  932.                         break;
  933.                     }
  934.                     if (a==1 && (tempfile=findfile(dwindow,namebuf,NULL))) {
  935.                         if (!noremove) removefile(tempfile,dwindow,inact,(tempfile->type!=file->type));
  936.                         exist=0;
  937.                     }
  938.                 }
  939.                 if (file->type>=ENTRY_DIRECTORY) {
  940.                     a=recursedir(sourcename,destname,R_COPY,0);
  941.                     if (exist) {
  942.                         byte=-1;
  943.                         exist=0;
  944.                     }
  945.                     else byte=dos_global_copiedbytes;
  946.                     if (config->copyflags©_DATE) setdate(destname,&file->date);
  947.  
  948.                     if (!a && !func_external_file[0]) {
  949.                         setdirsize(file,dos_global_bytecount,act);
  950.                         refreshwindow(act,0);
  951.                         filloutcopydata(file);
  952.                     }
  953.                     else if (a==-1 || a==-10) {
  954.                         if (a==-1) {
  955.                             if ((a=checkerror(globstring[STR_COPYING],file->name,IoErr()))==1)
  956.                                 goto functionloop;
  957.                             if (a==3) a=-10; 
  958.                         }
  959.                         if (CheckExist(destname,NULL)) {
  960.                             if (exist && (tempfile=findfile(dwindow,namebuf,NULL)))
  961.                                 removefile(tempfile,dwindow,inact,0);
  962.                             addfile(dwindow,inact,namebuf,byte,file->type,&file->date,
  963.                                 file->comment,file->protection,file->subtype,1,NULL,NULL,
  964.                                 file->owner_id,file->group_id);
  965.                         }
  966.                         if (a==-10) myabort();
  967.                         show=inact;
  968.                         break;
  969.                     }
  970.                     else if (a<0) break;
  971.                 }
  972.                 else {
  973.                     if (!(a=copyfile(sourcename,destname,&err,-1,NULL,0))) {
  974.                         doerror(err);
  975.                         if ((a=checkerror(globstring[STR_COPYING],file->name,err))==3) {
  976.                             myabort();
  977.                             break;
  978.                         }
  979.                         if (a==1) goto functionloop;
  980.                         break;
  981.                     }
  982.                     else if (a==-1) {
  983.                         myabort();
  984.                         break;
  985.                     }
  986.                     byte=file->size;
  987.                 }
  988.                 if (exist && (tempfile=findfile(dwindow,namebuf,NULL)))
  989.                     removefile(tempfile,dwindow,inact,0);
  990.                 if (lockandexamine(destname,&fileinfo)) {
  991.                     if (fileinfo.fib_DirEntryType<0) byte=fileinfo.fib_Size;
  992.                     addfile(dwindow,inact,
  993.                         fileinfo.fib_FileName,
  994.                         byte,
  995.                         fileinfo.fib_DirEntryType,
  996.                         &fileinfo.fib_Date,
  997.                         fileinfo.fib_Comment,
  998.                         fileinfo.fib_Protection,
  999.                         file->subtype,1,NULL,NULL,
  1000.                         fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
  1001.                     if (config->copyflags©_ARC && !(file->protection&FIBF_ARCHIVE)) {
  1002.                         if (SetProtection(sourcename,file->protection|FIBF_ARCHIVE)) {
  1003.                             file->protection|=FIBF_ARCHIVE;
  1004.                             getprot(file->protection,file->protbuf);
  1005.                         }
  1006.                     }    
  1007.                 }
  1008.                 okayflag=1;
  1009.                 show=inact;
  1010.                 break;
  1011.  
  1012.             case FUNC_HUNT:
  1013.                 if (file->type<=ENTRY_FILE) {
  1014.                     okayflag=1;
  1015.                     break;
  1016.                 }
  1017.                 if ((a=recursedir(sourcename,NULL,R_HUNT,0))==-3) {
  1018.                     wildselect(buf2,2,0);
  1019.                     findfirstsel(act,-2);
  1020.                     okayflag=breakout=noshow=1; count=-1;
  1021.                     break;
  1022.                 }
  1023.                 if (a>-1) {
  1024.                     okayflag=1;
  1025.                     if (a==0 && !func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
  1026.                     if (a>0) count+=a;
  1027.                 }
  1028.                 else count=-1;
  1029.                 break;
  1030.  
  1031.             case FUNC_READ:
  1032.             case FUNC_HEXREAD:
  1033.             case FUNC_ANSIREAD:
  1034.             case FUNC_SMARTREAD:
  1035.                 if (file->type>=ENTRY_DEVICE) {
  1036.                     okayflag=1;
  1037.                     break;
  1038.                 }
  1039.                 if ((a=viewfile(sourcename,file->name,function,NULL,
  1040.                     viewdata,(viewdata)?1:0,(entry_depth>1)))!=-2) {
  1041.                     if (a!=-3) ++count;
  1042.                     else if (count==0) unselect(act,file);
  1043.                     if (file->selected) {
  1044.                         file->selected=0;
  1045.                         if (swindow) {
  1046.                             --swindow->filesel; swindow->bytessel-=file->size;
  1047.                         }
  1048.                     }
  1049.                     SetBusyPointer(Window);
  1050.                     if (a==-1) status_justabort=1;
  1051.                     else okayflag=1;
  1052.                 }
  1053.                 else {
  1054.                     if (!count && !(doerror(IoErr()))) okayflag=1;
  1055.                 }
  1056.                 break;
  1057.  
  1058.             case FUNC_SHOW:
  1059.                 if (file->type>=ENTRY_DEVICE || file->size<1) {
  1060.                     okayflag=1;
  1061.                     file=NULL;
  1062.                     break;
  1063.                 }
  1064.                 if (entry_depth<2 &&
  1065.                     checkfiletypefunc(sourcename,FTFUNC_SHOW)) okayflag=1;
  1066.                 else {
  1067.                     if (data==0) {
  1068.                         if (swindow && swindow->filesel>1 && config->viewbits&VIEWBITS_SHOWBLACK) {
  1069.                             if (blankscreen=OpenScreen((struct NewScreen *)&blank_scr))
  1070.                                 SetRGB4(&blankscreen->ViewPort,0,0,0,0);
  1071.                             setnullpointer(Window);
  1072.                             pt=0;
  1073.                         }
  1074.                         data=1;
  1075.                     }
  1076.                     if ((a=showpic(sourcename,pt))==-1) {
  1077.                         okayflag=1;
  1078.                         myabort();
  1079.                         break;
  1080.                     }
  1081.                     else {
  1082.                         if (a==1) okayflag=1;
  1083.                         else file=NULL;
  1084.                     }
  1085.                 }
  1086.                 break;
  1087.  
  1088.             case FUNC_ICONINFO:
  1089.                 if (LStrCmpI(file->name,".info")==0) okayflag=1;
  1090.                 else {
  1091.                     if ((ptr=isicon(sourcename))) *ptr=0;
  1092.                     switch ((a=dopus_iconinfo(sourcename))) {
  1093.                         case -1:
  1094.                             myabort();
  1095.                             file=NULL;
  1096.                             break;
  1097.                         case -2:
  1098.                             dostatustext(globstring[STR_CANT_FIND_ICON]);
  1099.                             file=NULL;
  1100.                             break;
  1101.                         case -3:
  1102.                             dostatustext(globstring[STR_NO_CHIP_FOR_ICON]);
  1103.                             file=NULL;
  1104.                             break;
  1105.                         case -4:
  1106.                             file=NULL;
  1107.                             status_justabort=1;
  1108.                             break;
  1109.                         case 1:
  1110.                             if (act>-1) {
  1111.                                 StrCombine(buf,sourcename,".info",256);
  1112.                                 if (isicon(file->name)) {
  1113.                                     reload_file(act,sourcename);
  1114.                                     file=reload_file(act,buf);
  1115.                                 }
  1116.                                 else {
  1117.                                     file=reload_file(act,sourcename);
  1118.                                     reload_file(act,buf);
  1119.                                 }
  1120.                             }
  1121.                         default:
  1122.                             okayflag=1;
  1123.                             show=act;
  1124.                             break;
  1125.                     }
  1126.                 }
  1127.                 break;
  1128.  
  1129.             case FUNC_PLAYST:
  1130.                 a=1;    
  1131.             case FUNC_PLAY:
  1132.             case FUNC_LOOPPLAY:
  1133.                 if (file->type>=ENTRY_DEVICE || file->size<1) {
  1134.                     okayflag=1;
  1135.                     file=NULL;
  1136.                     break;
  1137.                 }
  1138.                 if (entry_depth<2 &&
  1139.                     checkfiletypefunc(sourcename,(function==FUNC_PLAY)?FTFUNC_PLAY:FTFUNC_LOOPPLAY))
  1140.                     okayflag=1;
  1141.                 else if (a || check_is_module(sourcename)) {
  1142.                     if ((a=playmod(sourcename)) && swindow && swindow->filesel>1) {
  1143.                         a=-1;
  1144.                         FOREVER {
  1145.                             Wait(1<<Window->UserPort->mp_SigBit);
  1146.                             while (getintuimsg()) {
  1147.                                 class=IMsg->Class; code=IMsg->Code;
  1148.                                 ReplyMsg((struct Message *)IMsg);
  1149.                                 if (class==MOUSEBUTTONS) {
  1150.                                     a=(code==SELECTDOWN);
  1151.                                     break;
  1152.                                 }
  1153.                             }
  1154.                             if (a!=-1) break;
  1155.                         }
  1156.                         FlushModule();
  1157.                         if (!a) myabort();
  1158.                         else okayflag=1;
  1159.                     }
  1160.                     else if (a) okayflag=1;
  1161.                     else file=NULL;
  1162.                 }
  1163.                 else {
  1164.                     a=doplay8svx(sourcename,(function==FUNC_LOOPPLAY));
  1165.                     kill8svx();
  1166.                     if (a==-1) {
  1167.                         myabort();
  1168.                         break;
  1169.                     }
  1170.                     else {
  1171.                         if (a==1) okayflag=1;
  1172.                         else {
  1173.                             handle8svxerror(a);
  1174.                             file=NULL;
  1175.                         }
  1176.                     }
  1177.                 }
  1178.                 break;
  1179.  
  1180.             case FUNC_ADDICON:
  1181.                 if (strlen(file->name)>25 || isicon(file->name)) {
  1182.                     okayflag=1;
  1183.                     file=NULL;
  1184.                     break;
  1185.                 }
  1186.                 StrCombine(buf2,file->name,".info",31);
  1187.                 StrCombine(destname,sourcename,".info",256);
  1188.                 if ((a=CheckExist(sourcename,NULL))==0) {
  1189.                     doerror((a=IoErr()));
  1190.                     if ((a=checkerror(globstring[STR_ADDING_ICON],file->name,a))==1)
  1191.                         goto functionloop;
  1192.                     if (a==3) {
  1193.                         myabort();
  1194.                         break;
  1195.                     }
  1196.                     file=NULL;
  1197.                     break;
  1198.                 }
  1199.                 if (a>0) data=ICONTYPE_DRAWER;
  1200.                 else if (checkexec(sourcename)) data=ICONTYPE_TOOL;
  1201.                 else data=ICONTYPE_PROJECT;
  1202.                 if (CheckExist(destname,NULL) && askeach) {
  1203.                     doerror(ERROR_OBJECT_EXISTS);
  1204.                     if (!(a=checkexistreplace(destname,destname,NULL,1,1))) {
  1205.                         file=NULL;
  1206.                         break;
  1207.                     }
  1208.                     else if (a==2) askeach=0;
  1209.                     else if (a==3) {
  1210.                         myabort();
  1211.                         break;
  1212.                     }
  1213.                 }
  1214.                 if ((iconwrite(data,destname))!=-1) {
  1215.                     if (lockandexamine(destname,&fileinfo)) {
  1216.                         addfile(swindow,act,buf2,fileinfo.fib_Size,-1,&fileinfo.fib_Date,
  1217.                             fileinfo.fib_Comment,fileinfo.fib_Protection,0,1,NULL,NULL,
  1218.                             fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
  1219.                         show=act;
  1220.                         okayflag=1;
  1221.                     }
  1222.                 }
  1223.                 else {
  1224.                     myabort();
  1225.                     break;
  1226.                 }
  1227.                 break;
  1228.  
  1229.             case FUNC_COMMENT:
  1230.                 if (askeach) {
  1231.                     if (rexx && rexx_argcount>0) strcpy(buf2,rexx_args[rexarg]);
  1232.                     else {
  1233.                         if (file->comment) strcpy(buf2,file->comment);
  1234.                         else buf2[0]=0;
  1235.                         if (!(a=whatsit(globstring[STR_ENTER_COMMENT],79,buf2,
  1236.                             globstring[STR_ALL]))) {
  1237.                             myabort();
  1238.                             break;
  1239.                         }
  1240.                         if (a==2) askeach=0;
  1241.                     }
  1242.                 }
  1243.                 FOREVER {
  1244.                     if (SetComment(sourcename,buf2)) break;
  1245.                     doerror((a=IoErr()));
  1246.                     if ((a=checkerror(globstring[STR_COMMENTING],file->name,a))==3) {
  1247.                         myabort();
  1248.                         break;
  1249.                     }
  1250.                     if (a!=1) {
  1251.                         file=NULL;
  1252.                         break;
  1253.                     }
  1254.                 }
  1255.                 if (status_justabort || !file) break;
  1256.                 okayflag=1;
  1257.                 if (file->type>=ENTRY_DIRECTORY) {
  1258.                     if ((a=recursedir(sourcename,buf2,R_COMMENT,0))>0 && status_justabort)
  1259.                         status_justabort=okayflag=0;
  1260.                     else if (!a && !func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
  1261.                 }
  1262.                 if (!noremove && file->comment!=dos_copy_comment) {
  1263.                     if (act>-1 && config->sortmethod[act]==DISPLAY_COMMENT) {
  1264.                         CopyMem((char *)file,(char *)&filebuf,sizeof(struct Directory));
  1265.                         removefile(file,swindow,act,0); file=NULL;
  1266.                         addfile(swindow,act,namebuf,filebuf.size,filebuf.type,&filebuf.date,
  1267.                             buf2,filebuf.protection,filebuf.subtype,1,NULL,NULL,
  1268.                             filebuf.owner_id,filebuf.group_id);
  1269.                     }
  1270.                     else {
  1271.                         if (file->comment)
  1272.                             LibFreePooled(dir_memory_pool,file->comment,strlen(file->comment)+1);
  1273.                         if (file->comment=LibAllocPooled(dir_memory_pool,strlen(buf2)+1))
  1274.                             strcpy(file->comment,buf2);
  1275.                     }
  1276.                 }
  1277.                 break;
  1278.  
  1279.             case FUNC_PROTECT:
  1280.                 if (askeach && !lastfile) {
  1281.                     if (rexx) {
  1282.                         data=rexx_arg_value[0];
  1283.                         mask=rexx_arg_value[1];
  1284.                     }
  1285.                     else {
  1286.                         data=file->protection;
  1287.                         if (!(a=getprotectdata(&data,&mask))) {
  1288.                             myabort();
  1289.                             break;
  1290.                         }
  1291.                         if (a==2) askeach=0;
  1292.                     }
  1293.                 }
  1294.                 temp=getnewprot(file->protection,data,mask);
  1295.                 FOREVER {
  1296.                     if (SetProtection(sourcename,temp)) break;
  1297.                     doerror((a=IoErr()));
  1298.                     if ((a=checkerror(globstring[STR_PROTECTING],file->name,a))==3) {
  1299.                         myabort();
  1300.                         break;
  1301.                     }
  1302.                     if (a!=1) {
  1303.                         file=NULL;
  1304.                         break;
  1305.                     }
  1306.                 }
  1307.                 if (status_justabort || !file) break;
  1308.                 file->protection=temp;
  1309.                 getprot(temp,file->protbuf);
  1310.                 if (file->type>=ENTRY_DIRECTORY) {
  1311.                     protstuff[0]=data; protstuff[1]=mask;
  1312.                     if ((a=recursedir(sourcename,NULL,R_PROTECT,(int)protstuff)) &&
  1313.                         status_justabort) break;
  1314.                     if (!a && !func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
  1315.                 }
  1316.                 if (!file->selected) refreshwindow(act,0);
  1317.                 okayflag=1;
  1318.                 break;
  1319.  
  1320.             case FUNC_ENCRYPT:
  1321.                 if (file->type>=ENTRY_DEVICE || file->size<1) {
  1322.                     okayflag=1;
  1323.                     file=NULL;
  1324.                     break;
  1325.                 }
  1326.                 StrCombine(destname,destdir,file->name,256);
  1327.                 if (CheckExist(destname,NULL)) {
  1328.                     if (askeach) {
  1329.                         if ((a=checkexistreplace(sourcename,destname,&file->date,1,1))) {
  1330.                             if (a==2) askeach=0;
  1331.                             else if (a==3) {
  1332.                                 myabort();    
  1333.                                 break;
  1334.                             }
  1335.                         }
  1336.                         else {
  1337.                             file=NULL;
  1338.                             break;
  1339.                         }
  1340.                     }
  1341.                     if ((a=delfile(destname,file->name,globstring[STR_DATESTAMPING],1,1))==-1) {
  1342.                         myabort();
  1343.                         break;
  1344.                     }
  1345.                 }
  1346.                 if (!CheckExist(destname,NULL)) {
  1347.                     FOREVER {
  1348.                         if (copyfile(sourcename,destname,&err,-1,buf2,data)) {
  1349.                             addfile(dwindow,inact,file->name,file->size,file->type,&file->date,
  1350.                                 file->comment,file->protection,file->subtype,1,NULL,NULL,
  1351.                                 file->owner_id,file->group_id);
  1352.                             okayflag=1; show=inact;
  1353.                             break;
  1354.                         }
  1355.                         doerror(err);
  1356.                         if ((a=checkerror(globstring[STR_ENCRYPTING],file->name,err))==3) {
  1357.                             myabort();
  1358.                             break;
  1359.                         }
  1360.                         if (a!=1) {
  1361.                             file=NULL;
  1362.                             break;
  1363.                         }
  1364.                     }
  1365.                 }
  1366.                 else doerror(ERROR_OBJECT_EXISTS);
  1367.                 break;
  1368.  
  1369.             case FUNC_DATESTAMP:
  1370.                 if (askeach && !lastfile) {
  1371.                     if (rexx && rexx_argcount>0) strcpy(buf2,rexx_args[rexarg]);
  1372.                     else {
  1373.                         buf2[0]=0;
  1374.                         if (!(a=whatsit(globstring[STR_ENTER_DATE_AND_TIME],20,buf2,
  1375.                             globstring[STR_ALL]))) {
  1376.                             myabort();
  1377.                             break;
  1378.                         }
  1379.                         if (a==2) askeach=0;
  1380.                     }
  1381.                     if (buf2[0]) {
  1382.                         parsedatetime(buf2,buf,buf1,&a);
  1383.                         strtostamp(buf,buf1,&datetime.dat_Stamp);
  1384.                     }
  1385.                     else DateStamp(&datetime.dat_Stamp);
  1386.                 }
  1387.                 FOREVER {
  1388.                     if ((a=setdate(sourcename,&datetime.dat_Stamp))==1) {
  1389.                         if (!noremove) {
  1390.                             if (act>-1 && config->sortmethod[act]==DISPLAY_DATE) {
  1391.                                 CopyMem((char *)file,(char *)&filebuf,sizeof(struct Directory));
  1392.                                 if (file->comment) {
  1393.                                     strcpy(buf2,file->comment);
  1394.                                     filebuf.comment=buf2;
  1395.                                 }
  1396.                                 removefile(file,swindow,act,0);
  1397.                                 file=(struct Directory *)addfile(swindow,act,filebuf.name,filebuf.size,
  1398.                                     filebuf.type,&datetime.dat_Stamp,filebuf.comment,filebuf.protection,
  1399.                                     filebuf.subtype,1,NULL,NULL,filebuf.owner_id,filebuf.group_id);
  1400.                             }
  1401.                             else {
  1402.                                 file->date.ds_Days=datetime.dat_Stamp.ds_Days;
  1403.                                 file->date.ds_Minute=datetime.dat_Stamp.ds_Minute;
  1404.                                 file->date.ds_Tick=datetime.dat_Stamp.ds_Tick;
  1405.                                 seedate(&file->date,file->datebuf,1);
  1406.                             }
  1407.                         }
  1408.                         break;
  1409.                     }
  1410.                     doerror(a);
  1411.                     if ((a=checkerror(globstring[STR_DATESTAMPING],file->name,a))==3) {
  1412.                         myabort();
  1413.                         break;
  1414.                     }
  1415.                     if (a!=1) {
  1416.                         file=NULL;
  1417.                         break;
  1418.                     }
  1419.                 }
  1420.                 if (status_justabort || !file) break;
  1421.                 if (file->type>=ENTRY_DIRECTORY) {
  1422.                     if (!(recursedir(sourcename,NULL,R_DATESTAMP,(int)&datetime.dat_Stamp))) {
  1423.                         okayflag=1;
  1424.                         if (!func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
  1425.                     }
  1426.                 }
  1427.                 else okayflag=1;
  1428.                 break;
  1429.  
  1430.             case FUNC_SEARCH:
  1431.                 if (file->type==ENTRY_DEVICE) {
  1432.                     if ((a=recursedir(file->name,NULL,R_SEARCH,0))==-2) {
  1433.                         okayflag=1;
  1434.                         count=-1; nextfile=NULL;
  1435.                         break;
  1436.                     }
  1437.                     if (a==-1) {
  1438.                         nextfile=NULL;
  1439.                         break;
  1440.                     }
  1441.                     if (a==-10) {
  1442.                         myabort();
  1443.                         break;
  1444.                     }
  1445.                     if (a>0) count+=a;
  1446.                     okayflag=1;
  1447.                 }
  1448.                 else {
  1449.                     if (file->type<=ENTRY_FILE) {
  1450.                         a=filesearch(sourcename,&b,(askeach)?1:-1);
  1451.                         count+=b;
  1452.                         if (a==2) {
  1453.                             okayflag=1; file=NULL;
  1454.                             busy();
  1455.                             if (act>-1) {
  1456.                                 if (swindow) {
  1457.                                     if (count>0) b=(swindow->filesel-count)+swindow->dirsel;
  1458.                                     else b=swindow->filesel+swindow->dirsel;
  1459.                                     if (!b) nextfile=NULL;
  1460.                                 }
  1461.                             }
  1462.                             if (nextfile && !simplerequest(globstring[STR_CONTINUE_WITH_SEARCH],
  1463.                                 globstring[STR_CONTINUE],str_cancelstring,NULL))
  1464.                                 nextfile=NULL;
  1465.                         }
  1466.                         if (a==-1) {
  1467.                             myabort();    
  1468.                             break;
  1469.                         }
  1470.                         if (a) {
  1471.                             okayflag=1;
  1472.                             if (a==3) file=NULL;
  1473.                             else if (a==4) {
  1474.                                 file=NULL;
  1475.                                 askeach=0;
  1476.                             }
  1477.                         }
  1478.                         else doerror(IoErr());
  1479.                     }
  1480.                     else {
  1481.                         if (!(a=recursedir(sourcename,NULL,R_SEARCH,0))) {
  1482.                             if (!func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
  1483.                             okayflag=1;
  1484.                         }
  1485.                         if (a==-2) {
  1486.                             okayflag=1; breakout=2;
  1487.                             count=-1; nextfile=NULL;
  1488.                             break;
  1489.                         }
  1490.                         if (a==-1 || a==-10) {
  1491.                             if (a==-10) {
  1492.                                 myabort();
  1493.                                 file=NULL;
  1494.                             }
  1495.                             else nextfile=NULL;
  1496.                             break;
  1497.                         }
  1498.                         if (a>0) count+=a;
  1499.                     }
  1500.                 }
  1501.                 break;
  1502.         }
  1503.  
  1504.         if (config->dynamicflags&UPDATE_FREE && show>-1) seename(show);
  1505.         if (breakout==1) break;
  1506.         if (file && okayflag) {
  1507.             if (file->selected) unselect(act,file);
  1508.             else refreshwindow(act,0);
  1509.         }
  1510.         if (status_justabort || breakout==2) break;
  1511.  
  1512.         if (doicons && !lastfile && okayflag && oldiconname[0]) {
  1513.             if (file=findfile(swindow,oldiconname,NULL)) {
  1514.                 if (file==nextfile) nextfile=file->next;
  1515.                 lastfile=1;
  1516.                 if (file->selected && prog_indicator) {
  1517.                     if (progtype==0 || progtype==2) {
  1518.                         ++value;
  1519.                         dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,value,total,NULL,0);
  1520.                     }
  1521.                 }
  1522.                 if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-2,0,file->name,1);
  1523.                 goto functionloop;
  1524.             }
  1525.             else {
  1526.                 StrCombine(sourcename,sourcedir,oldiconname,256);
  1527.                 if (filloutdummy(sourcename,&dummyfile)) {
  1528.                     dummyfile.selected=0;
  1529.                     file=&dummyfile;
  1530.                     lastfile=1;
  1531.                     goto functionloop;
  1532.                 }
  1533.             }
  1534.         }
  1535.  
  1536.         if (globflag) break;
  1537.         if (!lastfile && file && file->next && file->next!=nextfile) file=file->next;
  1538.         else file=nextfile;
  1539.         namebuf[0]=0;
  1540.     }
  1541.  
  1542.     if (prog_indicator) {
  1543.         dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-1,status_justabort,NULL,0);
  1544.         if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-1,status_justabort,NULL,1);
  1545.     }
  1546.  
  1547.     switch (function) {
  1548.         case FUNC_HUNT:
  1549.             if (count==0) {
  1550.                 okayflag=0;
  1551.                 doerror(ERROR_OBJECT_NOT_FOUND);
  1552.                 simplerequest(globstring[STR_COULD_NOT_FIND_FILE],globstring[STR_CONTINUE],NULL);
  1553.             }
  1554.             else if (count>0) {
  1555.                 lsprintf(buf2,globstring[STR_FOUND_MATCHING_FILES],count);
  1556.                 dostatustext(buf2);
  1557.                 simplerequest(buf2,globstring[STR_CONTINUE],NULL);
  1558.             }
  1559.             break;
  1560.  
  1561.         case FUNC_READ:
  1562.         case FUNC_HEXREAD:
  1563.         case FUNC_ANSIREAD:
  1564.         case FUNC_SMARTREAD:
  1565.             if (act>-1) refreshwindow(act,0);
  1566.             if (viewdata) cleanupviewfile(viewdata);
  1567.             if (status_justabort) myabort();
  1568.             else if (!okayflag && !(doerror(IoErr()))) okayflag=1;
  1569.             break;
  1570.  
  1571.         case FUNC_SHOW:
  1572.             if (config->viewbits&VIEWBITS_SHOWBLACK) {
  1573.                 if (blankscreen) {
  1574.                     CloseScreen(blankscreen);
  1575.                     blankscreen=NULL;
  1576.                 }
  1577.                 ClearPointer(Window);
  1578.             }
  1579.             break;
  1580.  
  1581.         case FUNC_COMMENT:
  1582.             if (status_flags&STATUS_IANSCRAP && okayflag) {
  1583.                 dostatustext(buf2);
  1584.                 okayflag=0;
  1585.             }
  1586.             break;
  1587.  
  1588.         case FUNC_PROTECT:
  1589.             if (status_flags&STATUS_IANSCRAP && okayflag) {
  1590.                 getprot(data,buf2);
  1591.                 dostatustext(buf2);
  1592.                 okayflag=0;
  1593.             }
  1594.             break;
  1595.  
  1596.         case FUNC_DATESTAMP:
  1597.             if (status_flags&STATUS_IANSCRAP && okayflag) {
  1598.                 seedate(&datetime.dat_Stamp,buf2,0);
  1599.                 dostatustext(buf2);
  1600.                 okayflag=0;
  1601.             }
  1602.             break;
  1603.  
  1604.         case FUNC_SEARCH:
  1605.             if (count>-1) {
  1606.                 if (count==0) simplerequest(globstring[STR_STRING_NOT_FOUND],
  1607.                     globstring[STR_CONTINUE],NULL);
  1608.                 else {
  1609.                     lsprintf(buf2,globstring[STR_MATCHED_FILES],count);
  1610.                     simplerequest(buf2,globstring[STR_CONTINUE],NULL);
  1611.                 }
  1612.                 okayflag=1;
  1613.             }
  1614.             break;
  1615.  
  1616.         case FUNC_BYTE:
  1617.             if (!status_justabort) {
  1618.                 main_proc->pr_WindowPtr=(APTR)-1;
  1619.                 if (!(filelock=Lock(destdir,ACCESS_READ))) value=0;
  1620.                 else {
  1621.                     Info(filelock,&infodata);
  1622.                     if (ramdisk_lock && CompareLock(filelock,ramdisk_lock)!=LOCK_DIFFERENT)
  1623.                         value=AvailMem(0);
  1624.                     else value=(infodata.id_NumBlocks-infodata.id_NumBlocksUsed)*blocksize;
  1625.                     UnLock(filelock);
  1626.                 }
  1627.                 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
  1628.                 if (specflags&FUNCFLAGS_BYTEISCHECKFIT) {
  1629.                     double needed,percent;
  1630.  
  1631.                     needed=data*blocksize;
  1632.                     if (value<1) percent=0;
  1633.                     else if (value>=needed || needed<1) {
  1634.                         percent=100;
  1635.                         retval=1;
  1636.                     }
  1637.                     else percent=100/(needed/value);
  1638.                     getfloatstr(percent,tbuf);
  1639.                     lsprintf(buf,globstring[STR_CHECKFIT_STRING],data*blocksize,value,tbuf);
  1640.                     dostatustext(buf);
  1641.                 }
  1642.                 else {
  1643.                     doselinfo(act);
  1644.                     strcat(str_select_info,
  1645.                         (value<=swindow->bytessel)?
  1646.                             globstring[STR_NO_FIT]:globstring[STR_YES_FIT]);
  1647.                     dostatustext(str_select_info);
  1648.                 }
  1649.                 okayflag=0;
  1650.             }
  1651.             break;
  1652.     }
  1653.  
  1654.     if (okayflag && !status_justabort) okay();
  1655.     if (!noshow) {
  1656.         endfollow(act);
  1657.         displaydir(act); seename(act);
  1658.     }
  1659.     if (inact>-1) {
  1660.         displaydir(inact);
  1661.         seename(inact);
  1662.     }
  1663.     switch (function) {
  1664.         case FUNC_DELETE:
  1665.         case FUNC_RENAME:
  1666.         case FUNC_MOVE:
  1667.         case FUNC_MOVEAS:
  1668.         case FUNC_ADDICON:
  1669.         case FUNC_ICONINFO:
  1670.             update_buffer_stamp(act,1);
  1671.             break;
  1672.  
  1673.         case FUNC_COMMENT:
  1674.         case FUNC_PROTECT:
  1675.         case FUNC_DATESTAMP:
  1676.             update_buffer_stamp(act,0);
  1677.             break;
  1678.     }
  1679.  
  1680.     switch (function) {
  1681.         case FUNC_MOVE:
  1682.         case FUNC_MOVEAS:
  1683.         case FUNC_COPY:
  1684.         case FUNC_COPYAS:
  1685.         case FUNC_ENCRYPT:
  1686.             update_buffer_stamp(inact,1);
  1687.             break;
  1688.     }
  1689.  
  1690.     switch (function) {
  1691.         case FUNC_SEARCH:
  1692.             if (count>0) rexx_return_value=count;
  1693.             break;
  1694.     }
  1695.  
  1696.     startnotifies();
  1697.  
  1698. endfunction:
  1699.     if (prog_indicator) dotaskmsg(hotkeymsg_port,PROGRESS_CLOSE,0,0,NULL,0);
  1700.     LFreeRemember(&funckey);
  1701.     --entry_depth;
  1702.     return(retval);
  1703. }
  1704.